#override("title")
SpringWind - 场地列表
#end
#override("css")
<link href="#springUrl('/static/css/plugins/bootstrap-table/bootstrap-table.min.css')" rel="stylesheet">
<link href="#springUrl('/static/js/plugins/umeditor/themes/default/css/umeditor.css')" type="text/css" rel="stylesheet">
<link href="#springUrl('/static/js/plugins/bootstrap-fileinput/css/fileinput.css')" type="text/css" rel="stylesheet">
#end
#override("breadcrumb")
<li><a>评分系统</a></li><li class="active"><strong>场地列表</strong></li><li class="active"><strong id="province">$!{province}</strong></li><li class="active"><strong id="city">$!{city}</strong></li>
#end
#override("content")
<div class="row">
    <form id="myForm" class="form-horizontal" enctype="multipart/form-data" autocomplete="off" data-validator-option="{theme:'default'}">
        <input type="hidden" name="id" value="$!{site.id}">
        <input type="hidden" name="provinceId" value="$!{provinceId}">
        <input type="hidden" name="cityId" value="$!{cityId}">
        <input type="hidden" name="province" value="$!{site.province}">
        <input type="hidden" name="city" value="$!{site.city}">
        <input type="hidden" name="dist" value="$!{site.dist}">
        <input type="hidden" name="score" value="$!{site.score}">
        <div class="form-group"><label class="col-sm-2 control-label">场地名称</label>
            <div class="col-sm-10">
                <input type="text"  class="input-s-sm2" name="siteName"   value="$!{site.siteName}"  placeholder="请输入场地名称" data-rule="场地名称:required;siteName">
            </div>
        </div>
        <div class="form-group"><label class="col-sm-2 control-label">场地简介</label>
            <div class="col-sm-10">
                <textarea  id="description" style="width: 50%;height:100px"  class="form-control social-comment textarea"    name="description"  placeholder="请输入场地简介" data-rule="场地简介:required;description"></textarea>
            </div>
        </div>
        <div class="form-group"><label class="col-sm-2 control-label">邮政编码</label>
            <div class="col-sm-10">
                <input type="text"  class="input-s-sm2" name="postCode"   value="$!{site.postCode}"  placeholder="邮政编码" data-rule="邮政编码:required;contact">
            </div>
        </div>
        <div class="form-group"><label class="col-sm-2 control-label">联系人</label>
            <div class="col-sm-10">
                <input type="text"  class="input-s-sm2" name="contact"   value="$!{site.contact}"  placeholder="联系人" data-rule="联系人:required;contact">
            </div>
        </div>

        <div class="form-group"><label class="col-sm-2 control-label">东经</label>
            <div class="col-sm-10">
                <input name="locationType" type="hidden"  value="1"/>
                <input type="text" class="input-s-sm2"  id="longitude" name="longitude" readonly value="$!{site.longitude}" placeholder="请输入东经" data-rule="东经:required;long">
            </div>
        </div>
        <div class="form-group"><label class="col-sm-2 control-label">北纬</label>
            <div class="col-sm-10">
                <input type="text" class="input-s-sm2"  id="latitude"  name="latitude" readonly value="$!{site.latitude}"  placeholder="请输入北纬" data-rule="北纬:required;lat">
            </div>
        </div>
        <div class="form-group"><label class="col-sm-2 control-label">地图</label>
            <div class="col-sm-10">
                <div id="allmap" style="width:800px;height:240px;"></div>
            </div>
        </div>

        <div class="form-group"><label class="col-sm-2 control-label">场地信息:</label>
            <div id="siteDetailDiv" class="col-sm-10">
                 <script type="text/plain"  name="siteDetail" id="siteDetail" style="width:800px;height:240px;">$!{site.siteDetail}</script>
                 <input id="siteFile"  name="siteFile"  value="$!{site.siteFile}" type="hidden"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">附件:</label>
            <div  class="col-sm-10" style="width: 55%;">
                <form enctype="multipart/form-data"class="col-sm-10" >
                    <a id="siteFileUrl" name="siteFileUrl" title="暂无文件" target="_blank"><font style="font-weight: 900;color: #3C9D40;">暂无文件</font></a>
                    <div class="file-loading"  style="width: 60%">
                        <input  name="siteFileUpload" id="siteFileUpload" class="file" style="width: 60%;" type="file" multiple data-min-file-count="1" >
                    </div>
                </form>
            </div>
        </div>
        <div class="form-group">
            <div class="text-center">
                <button class="btn btn-primary" onclick="saveSiteInfo()">保 存</button>
            </div>
        </div>
    </form>
</div>

#end
#override("js")
<script src="#springUrl('/static/js/plugins/bootstrap-table/bootstrap-table.min.js')"></script>
<script src="#springUrl('/static/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js')"></script>
<script src="#springUrl('/static/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js')"></script>
<script src="#springUrl('/static/plugins/layer-v2.2/layer/layer.js')"></script>
<script src="#springUrl('/static/js/common.js')"></script>
<script src="#springUrl('/static/plugins/nice-validator-0.8.1/jquery.validator.js')"></script>
<script type="text/javascript" charset="utf-8" src="#springUrl('/static/js/plugins/umeditor/umeditor.config.js')"></script>
<script type="text/javascript" charset="utf-8" src="#springUrl('/static/js/plugins/umeditor/umeditor.js')"></script>
<script type="text/javascript" src="#springUrl('/static/js/plugins/umeditor/lang/zh-cn/zh-cn.js')"></script>
<script type="text/javascript" src="#springUrl('/static/js/plugins/bootstrap-fileinput/js/fileinput.js')"></script>
<script type="text/javascript" src="#springUrl('/static/js/plugins/bootstrap-fileinput/js/locales/zh.js')"></script>
<script src="http://api.map.baidu.com/api?v=2.0&ak=2GlUhNFAKn4hBkQBkM39G303SE9XFDTc"></script>
<script type="text/javascript">

    var province ='${province}';
    var longitude='$!{site.longitude}';
    var latitude='$!{site.latitude}';
    // 百度地图API功能
    var mp = new BMap.Map("allmap");
    mp.enableScrollWheelZoom(true);
    mp.disableDragging();
    setTimeout(function(){
        mp.enableDragging();   //两秒后开启拖拽
        //map.enableInertialDragging();   //两秒后开启惯性拖拽
    }, 2000);
    // 将控件（平移缩放控件）添加到地图上
    mp.addControl(new BMap.NavigationControl());

    // 为地图增加点击事件，为input赋值
    mp.addEventListener("click", function(e) {
        mp.clearOverlays();//清空原来的标注
        $('#latitude').val(e.point.lat);
        $('#longitude').val(e.point.lng);
        var p1 = new BMap.Point(e.point.lng, e.point.lat);
        var marker = new BMap.Marker(p1);  // 创建标注
        mp.addOverlay(marker);              // 将标注添加到地图中
    });
    // 创建位置检索、周边检索和范围检索
    var local = new BMap.LocalSearch(mp, {
        renderOptions: {
            map: mp
        }
    });

    function theLocation() {
        var city = document.getElementById("cityName").value;
        if (city != "") {
            local.search(city);
        }
    };
    var um = UM.getEditor('siteDetail');
    um.addListener('blur',function(){
        $('#focush2').html('编辑器失去焦点了')
    });
    um.addListener('focus',function(){
        $('#focush2').html('')
    });
    !function(){
        $('#description').val('$!{site.description}');
        $('#siteFileUrl').attr("href",'$!{site.siteFile}');
        $('#siteFileUrl').html('$!{site.siteFile}');
        $("input[name='locationType'][value='$!{site.locationType}']").attr("checked",true);
        if(longitude!=''&&latitude!='')
        {    // 将标注添加到地图中
            var p1 = new BMap.Point(longitude, latitude);
            var marker = new BMap.Marker(p1);  // 创建标注
            mp.addOverlay(marker);
            mp.centerAndZoom(p1, 19);
        } else{
            mp.centerAndZoom('$!{city}', 19);
        }
    }();
    function saveSiteInfo()
    {
        if($("#myForm").validator()){
            var myForm = $("#myForm");
            $.ajax({
                url: "#springUrl('/site/save')",
                dataType: "json",
                data:myForm.serialize(),
                type: "POST",
                success: function(data){
                    if(data.success && data.data){
                        parent.layer.alert("保存成功",function(){
                            parent.layer.closeAll();
                        });
                        ///location.replace('site/list/'+$!{site.province}"/"+$!{site.city});
                    } else {
                    }
                }
            });
        }
    }
    $("#siteFileUpload").fileinput({
        theme: 'zh',
        language: 'zh',
        enctype: 'multipart/form-data',
        uploadAsync: true, //默认异步上传
        uploadUrl: "#springUrl('/siteFile/upLoad')", // you must set a valid URL here else you will get an error
        allowedFileExtensions: ['doc', 'docx', 'pdf'],
        overwriteInitial: false,
        showPreview : false, //是否显示预览
        maxFileSize: 1000,
        maxFilesNum: 10,
        validateInitialCount:true

    });
    //异步上传返回结果处理
    $("#siteFileUpload").on("fileuploaded", function (event, data, previewId, index) {
        var res = data.response;

        $("#siteFileUrl").text(res.fileName);
        $("#siteFile").val(res.fileName);
        $('#siteFileUrl').html(res.fileName);
    });
</script>
#end
#extends("/common/framework.html")